﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpShare.Management.Mmc.Views {
    public class SessionsListView : TypeDescriptorReportListView<Data.SessionInfo>, IEqualityComparer<Data.SessionInfo> {
        protected override IEnumerable<Data.SessionInfo> ListReportObjects() {
            try {
                var sessions = ((SharpShareSnapIn)this.SnapIn).ShareManager.Sessions;
                return sessions;
            } catch { }

            return Enumerable.Empty<Data.SessionInfo>();
        }

        protected override bool ShouldRefreshPeriodically {
            get {
                return true;
            }
        }
        protected override IEqualityComparer<Data.SessionInfo> ReportObjectComparer {
            get {
                return this;
            }
        }
        protected override Microsoft.ManagementConsole.ResultNode CreateResultNode(Data.SessionInfo reportObject) {
            var node =  base.CreateResultNode(reportObject);
            node.ImageIndex = (int)Icon.User;
            return node;
        }
        #region IEqualityComparer<SessionInfo> Members

        bool IEqualityComparer<Data.SessionInfo>.Equals(Data.SessionInfo x, Data.SessionInfo y) {
            return (x.Identifier.Equals(y.Identifier));
        }

        int IEqualityComparer<Data.SessionInfo>.GetHashCode(Data.SessionInfo obj) {
            return obj.Identifier.GetHashCode();
        }

        #endregion
    }
}
